package com.flight.view;

import com.flight.bean.AirInfo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Scanner;

public class Views {
    Scanner input = new Scanner(System.in);

    public int Menu(){
        System.out.println("********** 欢 迎 使 用 航 班 信 息 系 统 **********");
        System.out.println("请选择操作（1.列出所有航班；2.按起飞时间查询；3.按目的地查询；4.删除航班；5.更新航班；0.退出）");
        System.out.println("请输入选择：");
        String nums = input.nextLine();
        int num = 0;
        num = Integer.parseInt(nums);
        if (num < 0 || num >5){
            System.out.println("输入有误，请重新输入。");
            return Menu();
        }
        return num;
    }
    public void infoList(){
        System.out.println("编号\t航班号\t目的地\t起飞时间");
    }

    public String beginTime(){
        System.out.println("请输入起飞时间：(格式：2021-01-01)");
        String time = input.nextLine();
        if(time.length() != 10){
            System.out.println("请输入正确时间！");
            return beginTime();
        }
        return time;
    }

    public String address(){
        System.out.println("请输入目的地：");
        String address = input.nextLine();
        return address;
    }

    public String delete(){
        System.out.println("请输入要删除的航班号");
        String airId = input.nextLine();
        return airId;
    }
    public String update(){
        System.out.println("请输入要更改的航班号：");
        String airId = input.nextLine();
        return airId;
    }

    public void printAirInfo(List<AirInfo> list){
        for (AirInfo infos : list) {
            System.out.println(infos.getId()+"\t"+infos.getAirId()+"\t"+
                    infos.getAddress()+"\t\t"+infos.getAirDate());
        }
    }
    public void printInfo(int d){
        if (d > 0){
            System.out.println("操作成功！");
        }else{
            System.out.println("操作失败");
        }
    }
    public AirInfo isAirInfo(AirInfo airInfo) throws ParseException {

        if (airInfo != null){
            System.out.println("请输入新的航班号：");
            String newAirInfoId = input.nextLine();
            System.out.println("请输入新的目的地：");
            String newAddress = input.nextLine();
            System.out.println("请输入新的起飞日期：");
            String newDate = input.nextLine();
            AirInfo newAirInfo = new AirInfo();
            newAirInfo.setAirId(newAirInfoId);
            newAirInfo.setAddress(newAddress);
            newAirInfo.setTime(newDate);
            return newAirInfo;
        }else {
            System.out.println("请输入正确的航班号！");
        }
        return null;
    }

    public void bye(){
        System.out.println("欢迎下次继续使用！");
    }
}
